const User = require('./User');
const Pet = require('./Pet');
const Order = require('./Order');
const Caregiver = require('./Caregiver');
const Service = require('./Service');

// 定义模型关联关系

// User 与 Pet 的关系
User.hasMany(Pet, {
  foreignKey: 'ownerId',
  as: 'pets',
  onDelete: 'CASCADE'
});
Pet.belongsTo(User, {
  foreignKey: 'ownerId',
  as: 'owner'
});

// User 与 Caregiver 的关系
User.hasOne(Caregiver, {
  foreignKey: 'userId',
  as: 'caregiverProfile',
  onDelete: 'CASCADE'
});
Caregiver.belongsTo(User, {
  foreignKey: 'userId',
  as: 'user'
});

// User 与 Order 的关系 (作为客户)
User.hasMany(Order, {
  foreignKey: 'customerId',
  as: 'ordersAsCustomer',
  onDelete: 'CASCADE'
});
Order.belongsTo(User, {
  foreignKey: 'customerId',
  as: 'customer'
});

// Caregiver 与 Order 的关系
Caregiver.hasMany(Order, {
  foreignKey: 'caregiverId',
  as: 'ordersAsCaregiver'
});
Order.belongsTo(Caregiver, {
  foreignKey: 'caregiverId',
  as: 'caregiver'
});

module.exports = {
  User,
  Pet,
  Order,
  Caregiver,
  Service
};
